unit DBHelper;

interface

uses FIB, FIBDatabase, pFIBDatabase, FIBQuery, pFIBProps, pFIBDataSet,
      pFIBCacheQueries,cmDBUnit;


type
{ TDbHelper }

  TDbHelper = class(TObject)
  private
   fDB: TFIBDatabase;
   fTR: TFIBTransaction;
   fWTR: TFIBTransaction;

  protected

  public
    constructor Create;
    destructor Destroy; override;
  published
    function GetQuery(ASQL: string; fWrite: Boolean= false): TFIBQuery;
    function GetDataSet: TpFIBDataSet;
  end;

implementation

{ TDbHelper }

constructor TDbHelper.Create;
begin
  fTR:= cmDb.RT;
  fWTR:= cmDb.WT;
  fDB:= cmDb.DB;
end;

destructor TDbHelper.Destroy;
begin

  inherited;
end;

function TDbHelper.GetDataSet: TpFIBDataSet;
var
  DS: TpFIBDataSet;
begin
  DS:= TpFIBDataSet.Create(nil);
  DS.Database:= fDB;
  Result:= DS;
end;

function TDbHelper.GetQuery(ASQL: string; fWrite: Boolean): TFIBQuery;
begin
  case fWrite of
    true: begin
            Result:= GetQueryForUse(fWTR, ASQL);
            Result.Options:= [qoStartTransaction, qoAutoCommit];
          end
    else Result:= GetQueryForUse(fTR, ASQL);
  end;
end;

end.
